﻿/*验证必填项
条件 需要将待验证控件添加requireType属性,并设置其值为1
  验证数字
  需要将待验证控件添加class='number'
*/
$(document).ready(function () {
    $("input").hover(function () {
        $(this).css("border-color", "darkseagreen"); ;
    }, function () {
        $(this).css("border-color", "");
    }
)
})
//鼠标移开时验证
$("[requireType=1]:input").blur(function () {
    if (typeof (checkRequireData) != 'undefined') {
        if ($(this).attr("requireType") == 1) {
            checkRequireData($(this));
        }
    }
})
//鼠标移开时验证数字
$(".number").blur(function () {
    if (typeof (checkNumber) != 'undefined') {
        checkNumber($(this));
    }
})

var errorCount;
var length;
///克隆对象
(function ($) {
    $.fn.checkInputData =  function () {
        errorCount = 0;
        length=0;
        $(this).find("input").each(function (item) {
            if($(this).attr("requireType")==1)
            {
                length++;
                checkRequireData($(this));

            }
        });
        if (length == 0 || length == errorCount) {
            return 1;
        }
        else {
            return 0;
        }
    };
})(jQuery);

//必填项验证,调用时只需要传入字段名即可
var checkRequireData = function (obj) {
    var field = $("#" + obj.attr("id"));
    var td = $('#td' + obj.attr("id"));
    if (field.val() == "") {
        field.css("background-color", "mistyrose");
    }
    else {
        field.css("background-color", "");
        errorCount++;
    }
    return errorCount;
}
//验证数字
var checkNumber = function (obj) {
    //定义正则表达式部分
    var reg = /^\d+$/;
    if (obj.val().constructor === String) {
        var re = value.match(reg);
        return true;
    }
    alert('请输入数字');
    obj.val() = "";
}


//验证开始日期和结束日期 
//参数1:开始时间控件ID 参数2:结束时间控件ID
var checkBeginDateAndEndDate = function (txtbeginTimeId, txtendTimeId) {
    if ($("#" + txtendTimeId).val() < $("#" + txtbeginTimeId).val()) {
        alert('结束时间不能小于开始时间');
        return false;
    }
    else {
        return true;
    }

}


///------------------------------
///验证电话
///------------------------------
var fnCheckPhoneNo = function (phoneNo) {
    if (phoneNo == "" || phoneNo == undefined) {
        return;
    }
}


///------------------------------
///验证邮箱
///------------------------------
var fnCheckEmail = function (email) {
    if (email == "" || email == undefined) {
        return;
    }

}



///-----------------------------
///验证身份证
///-----------------------------
var fnCheckIDCard = function (IDCard) {
    if (IDCard == "" || IDCard == undefined) {
        return;
    }
}